import { defineStore } from "pinia";
import axios from "axios";
import { LoveTalk } from "./interface";
import piniaPersistConfig from "../helper/persist";
export const useLoveTalkStore = defineStore({
  id: "loveTalk",
  state: (): LoveTalk.talkStore => ({
    loveTalk:[]
  }),
  actions: {
    async addLoveTalk() {
      try {
        axios
          .get("https://api.uomg.com/api/rand.qinghua?format=json")
          .then((res: any) => {
            const { data } = res;
            console.log(data.content);
            let obj = {
              id: Math.random(),
              content: data.content,
            };
            this.loveTalk.unshift(obj as unknown as LoveTalk.loveInter);
          });
      } catch (error) {}
    },
  },
  persist: piniaPersistConfig(`loveTalk`),
});
